﻿annex_subject = {
	requires_approval = yes
	should_notify_third_parties = yes
	can_use_obligations = no

	potential = {
		scope:target_country = {
			is_direct_subject_of = root
			OR = {
				is_adjacent = root
				AND = {
					is_coastal = yes
					any_neighboring_state = {
						owner = { 
							is_adjacent = root
							is_direct_subject_of = root
						}
					}
				}
			}
			OR = {
				is_subject_type = subject_type_puppet
				is_subject_type = subject_type_vassal
				is_subject_type = subject_type_dependency
				is_subject_type = subject_type_real_union
			}
			NOT = { 
				is_country_type = colonial
			}
			overlord = { NOT = { is_subject_type = subject_type_customs_union } }
			#NOT = { overlord = { has_diplomatic_pact = { who = overlord type = customs_union } } 
		}
	}

	possible = {
		custom_tooltip = {
			text = already_integrating_tt
			NOT = {
				has_journal_entry = je_annex_subject_overlord
			}
		}

		bureaucracy >= 0 
		approaching_bureaucracy_shortage = no

		custom_tooltip = {
			text = annex_subject_institutions_tt

			OR = {
				AND = {
					scope:target_country = {
						is_subject_type = subject_type_dependency
					}
					institution_investment_level = {
						institution = institution_centralization
						value >= 3
					}
				}
				AND = {
					scope:target_country = {
						is_subject_type = subject_type_real_union
					}
					institution_investment_level = {
						institution = institution_centralization
						value >= 3
					}
				}
				AND = {
					scope:target_country = {
						OR = {
							is_subject_type = subject_type_puppet
						}
					}
					institution_investment_level = {
						institution = institution_centralization
						value >= 5
					}
				}
				AND = {
					scope:target_country = {
						OR = {
							is_subject_type = subject_type_vassal
						}
					}
					institution_investment_level = {
						institution = institution_centralization
						value >= 5
					}
				}
			}
		}

		is_revolutionary = no
		
		scope:target_country = {
			is_revolutionary = no
		}				

		is_at_war = no
		scope:target_country = { is_at_war = no }

	}
	
	accept_effect = {

		custom_tooltip = {
			text = annex_subject_tt
			scope:target_country = {
				add_journal_entry = {
					type = je_annex_subject_junior
				}
			}
			add_journal_entry = {
				type = je_annex_subject_overlord
			}
		}

	}
	
	ai = {
		check_acceptance_for_will_propose = yes

		accept_score = {
			value = 0

			add = {
				desc = "DIPLOMATIC_ACCEPTANCE_BASE"
				value = -30
			}
			
			if = {
				limit = {
					NOR = {
						scope:actor.market = {
							any_scope_country = {
								is_adjacent = root
							}
						}
						scope:actor = {
							has_diplomatic_pact = { who = root type = customs_union }
						}
					}
				}
				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_NOT_ADJACENT_MARKETS"
					value = -20
				}
			}			

			add = {
				desc = "DIPLOMATIC_ACCEPTANCE_GDP"
				value = "scope:actor.ai_gdp_comparison(root)"
				min = -10
				max = 10
			}
		
			if = {
				limit = {
					"scope:actor.ai_ideological_opinion(root)" > 0
				}
				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_IDEOLOGICAL_OPINION"
					value = "scope:actor.ai_ideological_opinion(root)"
					multiply = 0.5
					max = 20
				}					
			}
			else_if = {
				limit = {
					"scope:actor.ai_ideological_opinion(root)" < 0
				}
				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_IDEOLOGICAL_OPINION_NEGATIVE"
					value = "scope:actor.ai_ideological_opinion(root)"
					multiply = 0.5
					min = -20
				}					
			}	
			add = {
				desc = "DIPLOMATIC_ACCEPTANCE_ATTITUDE"
				if = {
					limit = {
						OR = {
							has_attitude = {
								who = scope:actor
								attitude = protective
							}
							has_attitude = {
								who = scope:actor
								attitude = domineering
							}
							has_attitude = {
								who = scope:actor
								attitude = loyal
							}							
						}
					}
					value = 40
				}
				if = {
					limit = {
						has_attitude = {
							who = scope:actor
							attitude = genial
						}
					}
					value = 30
				}				
				if = {
					limit = {
						OR = {
							has_attitude = {
								who = scope:actor
								attitude = conciliatory
							}	
							has_attitude = {
								who = scope:actor
								attitude = cooperative
							}							
						}
					}
					value = 20
				}
				if = {
					limit = {
						has_attitude = {
							who = scope:actor
							attitude = cautious
						}
					}
					value = -50
				}
				if = {
					limit = {
						OR = {
							has_attitude = {
								who = scope:actor
								attitude = antagonistic
							}
							has_attitude = {
								who = scope:actor
								attitude = belligerent
							}
							has_attitude = {
								who = scope:actor
								attitude = rebellious
							}
						}
					}
					value = -1000
				}
			}

			add = {
				desc = "DIPLOMATIC_ACCEPTANCE_RELATIONS"
				if = {
					limit = {
						"relations(scope:actor)" >= relations_threshold:amicable
						"relations(scope:actor)" < relations_threshold:friendly
					}
					value = 20
				}
				if = {
					limit = {
						"relations(scope:actor)" >= relations_threshold:friendly
					}
					value = 50
				}
			}

			add = {
				desc = "DIPLOMATIC_ACCEPTANCE_INFAMY"
				if = {
					limit = {
						"scope:actor.infamy" >= infamy_threshold:infamous
						"scope:actor.infamy" < infamy_threshold:notorious
					}
					value = -10
				}
				if = {
					limit = {
						"scope:actor.infamy" >= infamy_threshold:notorious
						"scope:actor.infamy" < infamy_threshold:pariah
					}
					value = -25
				}
				if = {
					limit = {
						"scope:actor.infamy" >= infamy_threshold:pariah
					}
					value = -50
				}
			}
		}

		propose_score = {
			value = 0
			
			if = {
				limit = {
					any_subject_or_below = {
						is_adjacent = root
						is_adjacent = scope:actor
					}
					scope:actor = {
						is_coastal = yes
					}
					NOT = {
						scope:actor = {
							NOT = { is_adjacent = root }
						}
					}
				}
				add = {
					value = 10
				}
			}
			
			if = {
				limit = {
					scope:actor = {
						is_subject_type = subject_type_real_union
					}
				}
				add = {
					value = -15
				}
			}
		}

		propose_break_score = {
			value = 10
		}

		use_obligation_chance = {
			value = 0
		}

		owe_obligation_chance = {
			value = 0
		}
	}
}